﻿using FEM.Result;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PGMHelper;

namespace PBSD_Development
{
    /// <summary>
    /// 单元组集合
    /// </summary>
    public class ElementGroupSetObj
    {
        /// <summary>
        /// 单元组集合
        /// </summary>
        private ElementGroupSet groupSet { set; get; }

        /// <summary>
        /// 单元组集合
        /// </summary>
        private Dictionary<string, ElementGroupObj> groupDict { set; get; }

        /// <summary>
        /// 单元组描述
        /// </summary>
        /// <returns> 单元组描述列表 </returns>
        public List<string> GetGroupDescps()
        {
            return this.groupDict.Keys.ToList();
        }

        /// <summary>
        /// 获得所有单元组
        /// </summary>
        /// <returns> 单元组对象列表 </returns>
        public List<ElementGroupObj> GetGroupList()
        {
            return this.groupDict.Values.ToList();
        }

        /// <summary>
        /// 获得所有框架单元组
        /// </summary>
        /// <returns> 框架单元组列表 </returns>
        public List<ElementGroupObj> GetFRAMEGroupList()
        {
            return (from eleGroup in this.GetGroupList()
                    where eleGroup.GroupTypeEnum == GroupType.FRAM
                    select eleGroup).ToList();
        }

        /// <summary>
        /// 获得所有墙单元组
        /// </summary>
        /// <returns> 墙单元组列表 </returns>
        public List<ElementGroupObj> GetWallGroupList()
        {
            return (from eleGroup in this.GetGroupList()
                    where eleGroup.GroupTypeEnum == GroupType.WALL
                    select eleGroup).ToList();
        }

        /// <summary>
        /// 获得单元组
        /// </summary>
        /// <param name="descp"></param>
        /// <returns></returns>
        private ElementGroupObj GetGroup(string descp)
        {
            //是否存在
            if (!this.groupDict.ContainsKey(descp))
            {
                MessageBoxExtern.Error(string.Format("单元组{0}不存在！", descp));
                return null;
            }
            return this.groupDict[descp];
        }

        /// <summary>
        /// 获得单元组
        /// </summary>
        /// <param name="descp"> 单元组描述 </param>
        /// <param name="group"> 单元组对象 </param>
        /// <returns> 是否存在 </returns>
        public bool GetGroup(string descp, out ElementGroupObj group)
        {
            //初始化
            group = new ElementGroupObj();
            //是否存在
            if (!this.groupDict.ContainsKey(descp)) return false;
            //获得单元组
            group = this.groupDict[descp];
            return true;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public ElementGroupSetObj()
        {
            //初始化
            this.groupDict = new Dictionary<string, ElementGroupObj>();
        }

        /// <summary>
        /// 构造结果
        /// </summary>
        /// <param name="resut"></param>
        public ElementGroupSetObj(FEMResult result) : this()
        {
            //获得单元组集合
            this.groupSet = result.ComponentResult.Groups;
            //遍历单元组
            foreach (var group in this.groupSet.Groups)
            {
                this.groupDict.Add(group.Descp, new ElementGroupObj(group, result));
            }
        }

    }
}
